/**
 * https://leetcode.cn/problems/count-complete-tree-nodes/submissions/
 * 222. 完全二叉树的节点个数
 * easy 陈贝纯 2024.09.17
 * 二分搜索
 */

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    int countNodes(TreeNode* root) {
        if(root==nullptr)
        return 0;
        return countNodes(root->left)+countNodes(root->right)+1;
    }
};